home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 January / Disc 3 / Amethyst.iso / rl / data / bin / make-sizes < prev    next >
Encoding:
Text File  |  2000-05-24  |  3.0 KB  |  117 lines

  1. #!/bin/sh
  2. # make-sizes
  3. # copyleft (c) 2000, joseph cheek, joseph@cheek.com.  released under MIT.
  4. # make-sizes:
  5. # create the file $BUILDROOT/col/data/sizes
  6. # $1 = RPMDIR
  7. # $2 = sizes file
  8. # ex: ./make-sizes ../../../../col24_gold/col/install/RPMS/ ../sizes
  9. # uses rpmshow, cut, printf
  10. # this file is a list of directories and sizes included with each of the
  11. # RPM packages included in a build.  It is used by lisa [and lizard?],
  12. # probably to figure out if there is enough disk space for the packages
  13. # you wish to install.
  14. # each time an RPM is rebuilt, this file needs to be rebuilt.  in
  15. # practice it should be rebuilt for each build IMHO.
  16.  
  17. # BUG: if the rpm lists files in dir1, then files in dir2, then files in
  18. # dir1 again, we don't aggregate the file sizes in dir1; instead dir1 gets
  19. # two totals, one for each set of files listed.
  20.  
  21. # BUG: this assumes 1K block sizes, and doesn't count space for directory
  22. # entries.  this follows Caldera's behavior.
  23.  
  24. # extract the data for each RPM
  25.  
  26. TMPFILE=/tmp/`basename $0`.$$
  27.  
  28. ( cd "$1"
  29.  
  30. # process each RPM file in a for loop
  31. # Caldera's file doesn't have an exact order for packages
  32. # ours is in ASCII order by package filename
  33. # this behavior matches Caldera's ~95%
  34.   for a in *
  35.   do
  36.  
  37. # first show the name of the RPM
  38.     RPM_NAME=`rpmextr --tag=name $a`
  39.     echo "[$RPM_NAME]"
  40.     DIR_NAME=""
  41.     DIR_SIZE=0
  42.  
  43. # get file info for each RPM
  44. # don't want pre or post scripts
  45. #    rpmshow $a 2> /dev/null| ( while read b
  46.     rpmextr --cpio $a | cpio -itv 2> /dev/null| ( while read b
  47.     do
  48.  
  49.       b=`echo "$b"`
  50.  
  51.       case "$b"
  52.       in
  53.  
  54. # only count regular files; all of these we can ignore
  55.     --empty-- | %pre* | %post* | l* | d* | b* | c* | p* )
  56.       continue
  57.       ;;
  58.  
  59.     -r* | --* )
  60. # these are the files to count.  round up to nearest 1K block and then
  61. # add to count.  check to be sure the directory here is the right one.
  62.  
  63. #first, get rounded up file size
  64.       FILE_SIZE=`echo $b | cut -d \  -f 5`
  65.       FILE_SIZE=$[ ($FILE_SIZE + 1023) / 1024 * 1024 ]
  66.  
  67. # then get dir name; keep only first three paths tho
  68.       FILE_DIR_NAME=/`echo $b | cut -d \  -f 9`
  69. # Caldera's script adds trailing / if dirname is less than three pathnames
  70. # they would put /usr/sbin/ where we put /usr/sbin
  71. # [cut 1-4 this time because of leading /]
  72.       FILE_DIR_NAME=`dirname $FILE_DIR_NAME | cut -d / -f 1-4`
  73.  
  74.       if [ "$FILE_DIR_NAME" != "$DIR_NAME" ]
  75.       then # new dir, output info on last dir
  76.         if [ "$DIR_SIZE" -gt 0 ]
  77.         then
  78.           printf "%-32s %s\\n" "$DIR_NAME" "$DIR_SIZE"
  79.         fi
  80.  
  81.         DIR_SIZE=0
  82.         DIR_NAME="$FILE_DIR_NAME"
  83.       fi
  84.  
  85.       DIR_SIZE=$[ $DIR_SIZE + $FILE_SIZE ]
  86.       ;;      
  87.  
  88.     *)
  89.       echo -e unknown in $RPM_NAME: $b\\a >&2
  90.       ;;
  91.  
  92.       esac
  93.  
  94.     done # get file info for each RPM
  95.  
  96. # output info on last dir
  97.     if [ "$DIR_SIZE" -gt 0 ]
  98.     then
  99.       printf "%-32s %s\\n" "$DIR_NAME" "$DIR_SIZE"
  100.     fi
  101.  
  102.   ) > "$TMPFILE"
  103. # sort differs from Caldera's version; their's seems to be in no
  104. # particular order
  105.   sort "$TMPFILE"
  106.  
  107.   done # process each RPM file in a for loop
  108.  
  109. ) > "$2"
  110.  
  111. rm "$TMPFILE"
  112.